package com.hsu.hiring.talent.dao;

import java.util.ArrayList;
import java.util.List;

import com.hsu.hiring.common.util.DBUtil;
import com.hsu.hiring.talent.entity.TalentEntity;

/**
 * Talent Dao
 *
 * @author Hsu.
 * @since 2016年1月14日
 */
public class TalentDao {

	/**
	 * 求职者注册
	 * 
	 * @param talent
	 * @return
	 * @throws RuntimeException
	 */
	public int resiter(TalentEntity talent) {
		String sql = "INSERT INTO talent VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)";
		List<Object> paramList = new ArrayList<>();
		paramList.add(talent.getCode());
		paramList.add(talent.getPassword());
		paramList.add(talent.getName());
		paramList.add(talent.getPhone());
		paramList.add(talent.getEmail());
		paramList.add(talent.getAge());
		paramList.add(talent.getGender());
		paramList.add(talent.getHobby());
		return DBUtil.executeUpdate(sql, paramList);
	}

	/**
	 * 求职者登录
	 * 
	 * @param code
	 * @param password
	 * @return
	 * @throws RuntimeException
	 */
	public TalentEntity login(String code, String password) {
		String sql = "SELECT id,name FROM talent WHERE code=? AND password=?";
		return DBUtil.getUniqueResult(TalentEntity.class, sql, code, password);
	}

	/**
	 * 求职者个人资料查询
	 * 
	 * @param id
	 * @return
	 * @throws RuntimeException
	 */
	public TalentEntity get(int id) {
		String sql = "SELECT * FROM talent WHERE id=?";
		return DBUtil.getUniqueResult(TalentEntity.class, sql, id);
	}

}
